﻿using System;
using System.Web.Http;
using eCommMongo.Core;
using eCommMongo.Service.Customers;
using yiCommerce.Core;
using yiCommerce.Service.Messages;

namespace eCommMongo.Web.Controllers.api
{

    public class SaveLogResult
    {
        public string Status { get; set; }

        public string Message { get; set; }
    }

    public class SaveLogRequest
    {
        public string PictureId { get; set; }
    }

    public class SaveCustomerInfoRequest
    {
        public int Id { get; set; }
        public string Intro { get; set; }
        public string NickName { get; set; }
    }


    public class SaveCustomerInfoResult
    {
        public string Status { get; set; }

        public string Message { get; set; }
        
    }

    public class CustomerApiController : ApiController
    {

        private ICustomerService _customerService;
        private IWorkContext _workContext;
        private IMessageService _messageService;

        public CustomerApiController(ICustomerService customerService, IWorkContext workContext, IMessageService messageService)
        {
            _customerService = customerService;
            _workContext = workContext;
            _messageService = messageService;
        }


        public SaveLogResult SaveLog(SaveLogRequest request)
        {
            var result = new SaveLogResult();

            try
            {

                _customerService.UpdateCustomerLogo(_workContext.CurrentCustomer.Id,  request.PictureId);
                result.Status = "0";
            }
            catch (Exception e)
            {
                result.Status = "1";
                result.Message = e.Message;

            }


            return result;
        }

        public SaveCustomerInfoResult SaveCustomerInfo(SaveCustomerInfoRequest request)
        {
            var result = new SaveCustomerInfoResult();
            try
            {


                _customerService.UpdateCustomerInfo(_workContext.CurrentCustomer.Id, request.NickName, request.Intro );
                result.Status = ConstInfo.ResultSuccessStatus;
                result.Message = _messageService.GetResourceValue(Messages.CustomerInfo_Update_Successfully, 0);
            }
            catch (Exception e)
            {
                result.Status = ConstInfo.ResultFailedStatus;
                result.Message = e.Message;
            }

            return result;
        }

    }
}
